#!/usr/bin/env/python3.7
# -*- coding: utf-8 -*-

"""
@File    : main.py
@Time    : 12/07/2021
@Author  : Silence
@Version : 1.0
@Contact : silence2021silence@163.com
@License : (C)Copyright 2021-2021, Silence
@Desc    : None
"""

import time
import pymysql
import threading
import read_arduino
import gpios
import record_audio
import upload_sensor
import check_audio

class Main():
    def record_audio():
        t = True
        while t:
            click = gpios.Button.click_return(init='init')
            if click == 0:
                        gpios.Gpios.buzzer(beep='beep',step=1)
                        # 1s = 10000
                        record_audio.RecordAudio.record_audio(length=30000)
                        gpios.Gpios.buzzer(beep='beep',step=2)
                        t = False
            if click == 2:
                pass
            if click == '':
                gpios.Gpios.buzzer(beep='unbeep',step=0)
                gpios.Gpios.led(bright='unbright',step=0)
            time.sleep(0.1)

    def upload_sensor():
        while True:
            upload_sensor.UploadSensor.upload_sensor()
            time.sleep(5)

    def check_audio():
        t = True
        while t:
            value = check_audio.CheckAudio.check_audio()
            if value == 'none':
                gpios.Gpios.led(bright='unbright',step=0)
            else:
                gpios.Gpios.led(bright='bright',step=0)
                t = False
            time.sleep(1)

if __name__ == '__main__':
    # Main.record_audio()
    # Main.upload_sensor()
    Main.check_audio()
